import { useCallback } from "react";
import { useDispatch, useSelector } from "react-redux";
import Creator from "../store/actions";
import OrderApi from "../api/indent";

export const useOrder = () => {
    const dispatch = useDispatch();
    const data = useSelector(state => state.useOrder);
    const { userId, genre, rows } = data;
    //    更新rows
    const order = useCallback(async () => {
        const data = await OrderApi.get({ userId, genre });
        dispatch(Creator.orderGet(data));
    }, [userId, genre, dispatch]);
    // 更新获取订单状态
    const State = useCallback(async (ste) => {
        dispatch(Creator.postState({ ste }));
    }, [dispatch]);
    return [rows, genre, { order, State }]
}
